package com.coldchain.gate.route;

import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @ClassName RouteDynamicFilterUtils
 * @Description TODO
 * @Author fangliai
 * @Date 2018/8/30 12:52
 * @Vesion 1
**/
public final class RouteDynamicFilterUtils {
    /**
     * 忽略认证的路径
     */
    private   static CopyOnWriteArraySet<String> ignoreAuthRoutes=new CopyOnWriteArraySet<>();


    public static  boolean ignore(String url){
        for (String s:ignoreAuthRoutes) {
            if(url.startsWith(s)){
                return true;
            }
        }
       return false;
    }

    /**
     * 添加路径并过虑掉非法的路径
     * @param path
     */
    public  static void addRoutePath(String path){
         String newPath=path.replace("/**","");
         if(newPath.length()>1){
             ignoreAuthRoutes.add(newPath);
         }
    }


    public  static void clear(){
         ignoreAuthRoutes.clear();
    }

}
